(function(){

/**
 * Created by shen'jia on 15/6/11.
 */
'use strict';
angular.module('controllers.oldOMDisplay.oldSystemPerform')
  .controller('adPerformCtrl',adPerformCtrl)//新增响应时间Ctrl
  .controller('mdifyPerformCtrl',mdifyPerformCtrl)//修改响应时间Ctrl
  .controller('chaKanPerformCtrl',chaKanPerformCtrl)
  .controller('chaKanP',chaKanP);

function adPerformCtrl($scope, $mdDialog, $timeout,oldSystemPerformData,oldSystemPerformURL) {
  $scope.selector={};
  $scope.selector.translate={};
  $scope.pageData = {
    system:'统一支付',
    province:'广东',
    business:'签约',
    timeTypeName:'天'
  };
  // $scope.system='11';
  // $scope.province='200';
  // $scope.business='02';
  $scope.selector = oldSystemPerformData;                                        //下拉列表的数据
  $scope.queryBusiness = oldSystemPerformURL.getSysBusiness;
  $scope._getNames = function (series, propertyName, objArr) {
    if (angular.isArray(series)) {
      if (series.length === objArr.length) {
        return '全部';
      }
      var arrName = series.map(function (item) {
        if (!item) {
          return undefined;
        }
        return item[propertyName];
      });
      return arrName.join(',');
    } else {
      return series[propertyName];
    }
  };
  $scope._checkAll = function (series, propertyName) {
    $timeout(function () {
      series[propertyName] = [];
    });
  };
  $scope.timesV = [
    '00:00','01:00','02:00','03:00','04:00','05:00','06:00','07:00','08:00','09:00','10:00',
    '11:00','12:00','13:00','14:00','15:00','16:00','17:00','18:00','19:00','20:00','21:00','22:00','23:00'
  ];
  $scope.zuida = [];
  for(var i=0;i<24;i++){
    $scope.zuida.push({});
  }
  $scope.Info = {
    currentAvgResponseTime: [],
    historyAvgResponseTime: [],
    responseTimeMax: [],
    responseTimeMin: []
  };//所填的数据对象
  $scope.addMax = function(name,pp,p2){
    $scope.Info[name][p2] = pp;
  }

  /**
   * [cancel Turn Off]
   * @return {[type]} [function]
   */
  $scope.cancel = function() {
    $mdDialog.cancel();
  };

  /**
   * [queding save]
   * @param  {[obj]} answer [Form infomation object]
   * @return {[type]}       [function]
   */
  $scope.queding = function(answer) {
    // if($scope.addForm.$invalid === undefined || $scope.addForm.$invalid){ //if form invalid ,not submitted
    //   return;
    // }
    for(var i=0;i<24;i++){
      $scope.Info.responseTimeMax[i] = $scope.Info.responseTimeMax[i] === undefined ? '':$scope.Info.responseTimeMax[i];
      $scope.Info.responseTimeMin[i] = $scope.Info.responseTimeMin[i] === undefined ? '':$scope.Info.responseTimeMin[i];
      $scope.Info.historyAvgResponseTime[i] = $scope.Info.historyAvgResponseTime[i] === undefined ? '':$scope.Info.historyAvgResponseTime[i];
      $scope.Info.currentAvgResponseTime[i] = $scope.Info.currentAvgResponseTime[i] === undefined ? '':$scope.Info.currentAvgResponseTime[i];
    }
    $scope.Info.pageData = $scope.pageData;
    $scope.Info.times = {
      startTime:$scope.selector.translate.startTime,
      endTime:$scope.selector.translate.endTime
    };
    $mdDialog.hide($scope.Info);
  };
}

function mdifyPerformCtrl($scope, oldSystemPerformData,oldSystemPerformURL,$mdDialog) {

  $scope.selector = oldSystemPerformData;                                        //下拉列表的数据
  $scope.queryBusiness = oldSystemPerformURL.getSysBusiness;
  $scope._getNames = function (series, propertyName, objArr) {
    if (angular.isArray(series)) {
      if (series.length === objArr.length) {
        return '全部';
      }
      var arrName = series.map(function (item) {
        if (!item) {
          return undefined;
        }
        return item[propertyName];
      });
      return arrName.join(',');
    } else {
      return series[propertyName];
    }
  };
  $scope._checkAll = function (series, propertyName) {
    $timeout(function () {
      series[propertyName] = [];
    });
  };
  $scope.timesV = [
    '00:00','01:00','02:00','03:00','04:00','05:00','06:00','07:00','08:00','09:00','10:00',
    '11:00','12:00','13:00','14:00','15:00','16:00','17:00','18:00','19:00','20:00','21:00','22:00','23:00'
  ];
  $scope.zuida = [];
  for(var i=0;i<24;i++){
    $scope.zuida.push({});
  }
  $scope.Info = {
    currentAvgResponseTime: [],
    historyAvgResponseTime: [],
    responseTimeMax: [],
    responseTimeMin: []
  };//所填的数据对象
  $scope.addMax = function(name,pp,p2){
    oldSystemPerformData.modifyData[name][p2] = pp;
    // $scope.Info[name][p2] = pp;
  }

  oldSystemPerformURL.modifyQuery();
  $scope.htmlData = oldSystemPerformData.modifyData;
  // $scope.userInfo = $cookieStore.get('userMngInfo');

  $scope.clearData = function(){
    angular.forEach(oldSystemPerformData.modifyData.responseTimeMax, function(role,key) {
      oldSystemPerformData.modifyData.responseTimeMax[key] = '';
      oldSystemPerformData.modifyData.responseTimeMin[key] = '';
      oldSystemPerformData.modifyData.currentAvgResponseTime[key] = '';
      oldSystemPerformData.modifyData.historyAvgResponseTime[key] = '';
    });
  };

  /**
   * [cancel Turn Off]
   * @return {[type]} [function]
   */
  $scope.cancel = function() {
    oldSystemPerformData.modifyData.responseTimeMax = [];
    oldSystemPerformData.modifyData.responseTimeMin = [];
    oldSystemPerformData.modifyData.currentAvgResponseTime = [];
    oldSystemPerformData.modifyData.historyAvgResponseTime = [];
    $mdDialog.cancel();
  };

  /**
   * [queding save]
   * @param  {[obj]} answer [Form infomation object]
   * @return {[type]}        [function]
   */
  $scope.queding = function(answer) {
    // if($scope.modifyForm.$invalid === undefined || $scope.modifyForm.$invalid){ //if form invalid ,not submitted
    //   return;
    // }
    $mdDialog.hide();

  };
}

function chaKanPerformCtrl($scope,oldSystemPerformData,$mdDialog,oldSystemPerformURL,oldSystemPerformOption){
  $scope.selector = oldSystemPerformData;
  $scope.provin = oldSystemPerformData.chaProvince;

  $scope.timesV = [
    '00:00','01:00','02:00','03:00','04:00','05:00','06:00','07:00','08:00','09:00','10:00',
    '11:00','12:00','13:00','14:00','15:00','16:00','17:00','18:00','19:00','20:00','21:00','22:00','23:00'
  ];
  $scope.zuida = [];
  for(var i=0;i<24;i++){
    $scope.zuida.push({});
  }
  oldSystemPerformURL.modifyQuery();
  $scope.htmlData = oldSystemPerformData.modifyData;
  $scope._getNames = function (series, propertyName, objArr) {
    if (angular.isArray(series)) {
      if (series.length === objArr.length) {
        return '全部';
      }
      var arrName = series.map(function (item) {
        if (!item) {
          return undefined;
        }
        return item[propertyName];
      });
      return arrName.join(',');
    } else {
      return series[propertyName];
    }
  };
  $scope._checkAll = function (series, propertyName) {
    $timeout(function () {
      series[propertyName] = [];
    });
  };
  var sysChart = echarts.init(document.getElementById('sysPerfm')); //初始化echarts
  var option = oldSystemPerformOption.sysPerformChart;                                     //echarts的option
  $scope.searchST = function(){

    var businessNN = $scope._getNames($scope.selector.translate.business,'businessName',$scope.selector.business);
    var systemN = $scope.selector.translate.system.length > 0 ? $scope.selector.translate.system[0].systemName : '全部系统';
    var businessN = $scope.selector.translate.business.length > 0 ? businessNN : '全部业务';
    var title = systemN + businessN + '响应时间';
    oldSystemPerformURL.querySysPerfm(sysChart,option,title,false);
  };
  $scope.searchST();
  $scope.cancel = function() {
    $mdDialog.cancel();
  };
  $scope.queding = function(answer) {
    $mdDialog.hide(answer);
  };


}

//新增的单独查看
function chaKanP($scope,oldSystemPerformData,$mdDialog,oldSystemPerformURL,oldSystemPerformOption,oldSystemPerformAddData){
  $scope.selector = oldSystemPerformAddData.addDate;
  $scope.provin = oldSystemPerformData.chaProvince;

  $scope.timesV = [
    '00:00','01:00','02:00','03:00','04:00','05:00','06:00','07:00','08:00','09:00','10:00',
    '11:00','12:00','13:00','14:00','15:00','16:00','17:00','18:00','19:00','20:00','21:00','22:00','23:00'
  ];
  $scope.zuida = [];
  for(var i=0;i<24;i++){
    $scope.zuida.push({});
  }
  // oldSystemPerformURL.modifyQuery();
  $scope.htmlData = oldSystemPerformAddData.addDate.data;
  var sysChart = echarts.init(document.getElementById('sysPerfm')); //初始化echarts
  var option = oldSystemPerformOption.sysPerformChart;                                     //echarts的option
  $scope.searchST = function(){

    // var businessNN = $scope._getNames($scope.selector.busName,'businessName',$scope.selector.business);
    // var systemN = $scope.selector.translate.system.length > 0 ? $scope.selector.translate.system[0].systemName : '全部系统';
    // var businessN = $scope.selector.translate.business.length > 0 ? businessNN : '全部业务';
    var title = $scope.selector.sysName + $scope.selector.busName + '响应时间';
    oldSystemPerformURL.queryWatchAdd(sysChart,option,title,false,oldSystemPerformAddData.addDate.yuanData);
  };
  $scope.searchST();
  $scope.cancel = function() {
    $mdDialog.cancel();
  };
  $scope.queding = function(answer) {
    $mdDialog.hide(answer);
  };


}
})();